package com.risk.management.task;

import com.risk.management.service.RiskResponseService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class RiskResponseCheckTask {

    @Autowired
    private RiskResponseService riskResponseService;

    /**
     * 每天凌晨2点检查逾期的风险响应计划
     */
    @Scheduled(cron = "0 0 2 * * ?")
    public void checkOverdueRiskResponses() {
        log.info("开始检查逾期的风险响应计划");
        try {
            int count = riskResponseService.checkAndUpdateOverdueResponses();
            log.info("发现{}个逾期的风险响应计划", count);
        } catch (Exception e) {
            log.error("检查逾期风险响应计划时发生错误", e);
        }
    }
} 